﻿using System.Collections.Generic;
using System.Text;
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using System.IO;

namespace Ramparts
{
    class MoveTowardShore : I_Strategy
    {
        private World world;
        private GameComponent gameComponent;

        public MoveTowardShore(GameComponent gameComponent, World world)
        {
            this.gameComponent = gameComponent;
            this.world = world;
        }

        public void performAction(GameComponent gameComponenet, World world)
        {
            moveTowardsShore();
            Console.WriteLine("Executing strategy: move towards shore");
        } 
       
        public void performAction()
        {
            moveTowardsShore();
            Console.WriteLine("Executing strategy: move towards shore");
        }


        // TODO Make this more better, have it try to move sideways
        // ALSO ONLY SET THE SHORE POSITION ONCE PERHAPS. 
        public void moveTowardsShore()
        {
            Vector2 tilePos = world.groundLayer.onTile(gameComponent.position);
            int shoreDirectionY = 0;

            int currentY = (int)tilePos.Y;

            while (currentY < world.groundLayer.gridHeight && shoreDirectionY != 0)
            {
                if (world.groundLayer.getGridValueAt((int)tilePos.X, currentY) == 1)
                {
                    shoreDirectionY = 1;
                }
                currentY++;
            }

            if (shoreDirectionY == 0)
            {
                shoreDirectionY = -1;
            }

            gameComponent.position = world.worldHelper.attemptMove((int)gameComponent.position.X, (int)gameComponent.position.Y, 0, shoreDirectionY);

        }

        

    }
}
